﻿/*
 * Copyright 2008 Pimm Hogeling, Karim Sempel and Demian Sempel
 * 
 * This file is part of 8bitplays.
 * 
 * 8bitplays is free software: you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation, either version 3 of the License, or (at your
 * option) any later version.
 * 
 * 8bitplays is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with 8bitplays. If not, see <http://www.gnu.org/licenses/>.
 */
package nl.sandmen.team.gui {
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.MouseEvent;
	/**
	 * @author Team Sandmen
	 */
	public class PlaybackButtons extends Sprite {
		[Embed(source="../../../../../media/Buttons.swf", symbol="PlaybackButtons")]
		private static const ASSET:Class;
		public var next:MovieClip;
		public var nextAlbum:MovieClip;
		public var playPause:MovieClip;
		public var previous:MovieClip;
		public var previousAlbum:MovieClip;
		public function PlaybackButtons():void {
			playPause = getAssetClip();
			previous = getAssetClip();
			next = getAssetClip();
			previousAlbum = getAssetClip();
			nextAlbum = getAssetClip();
			addChild(playPause);
			addChild(previous);
			addChild(next);
			addChild(previousAlbum);
			addChild(nextAlbum);
			previous.x = -48;
			next.x = 48;
			previousAlbum.x = -256;
			nextAlbum.x = 256;
			previous.y = 16;
			next.y = 16;
			previousAlbum.y = -192;
			nextAlbum.y = -192;
			playPause.gotoAndStop(5);
			previous.gotoAndStop(1);
			next.gotoAndStop(3);
			previousAlbum.gotoAndStop(11);
			nextAlbum.gotoAndStop(9);
		}
		private function getAssetClip():MovieClip {
			var movieClip:MovieClip = new ASSET();
			movieClip.buttonMode = true;
			movieClip.mouseChildren = false;
			movieClip.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
			return movieClip;
		}
		private function mouseOut(e:MouseEvent):void {
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT, mouseOut);
			e.currentTarget.addEventListener(MouseEvent.MOUSE_OVER, mouseOver);
			e.currentTarget.prevFrame();
		}
		private function mouseOver(e:MouseEvent):void {
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_OVER, mouseOver);
			e.currentTarget.addEventListener(MouseEvent.MOUSE_OUT, mouseOut);
			e.currentTarget.nextFrame();
		}
		public function setPlayState(value:Boolean):void {
			const c:uint = playPause.currentFrame;
			if (value) {
				if (c < 7) {
					playPause.gotoAndStop(c + 2);
				}
			} else {
				if (c > 6) {
					playPause.gotoAndStop(c - 2);
				}
			}
		}
	}
}